<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" v-if='action'>
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('商城订单')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record" v-if='action'>
           <a @click="handleEdit(record)" v-if=" record.actstatus == 0">编辑</a>
          <act-apply-btn @success="loadData" :data-id="record.id" :serviceName="serviceName" :variables="record"  v-if=" record.actstatus == 0 || record.actstatus == 3"></act-apply-btn>
          <act-handle-btn @success="loadData" :data-id="record.id" :type="0" text="通过" v-if=" record.actstatus == 1"></act-handle-btn>
          <act-handle-btn @success="loadData" :data-id="record.id" :type="1" text="驳回" v-if=" record.actstatus == 1"></act-handle-btn>
          <act-handle-btn @success="loadData" :data-id="record.id" :type="2" text="退回" v-if=" record.actstatus == 1"></act-handle-btn>
          <act-cancel-btn @success="loadData" :data-id="record.id" v-if=" record.actstatus == 1"></act-cancel-btn>
          <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <erp-mallorder-modal ref="modalForm" @ok="modalFormOk"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpMallorderModal from './modules/ErpMallorderModal'
  import '@/assets/less/TableExpand.less'
  import ActApplyBtn from "@views/flowable/components/ActApplyBtn";
  import ActCancelBtn from "@views/flowable/components/ActCancelBtn";
  import ActHandleBtn from "@views/flowable/components/ActHandleBtn";
  import ActHistoricDetailBtn from "@views/flowable/components/ActHistoricDetailBtn";


  export default {
    name: "ErpMallorderList",
    mixins:[JeecgListMixin],
    components: {
     ActHistoricDetailBtn, ActApplyBtn,ActCancelBtn,ActHandleBtn,
      ErpMallorderModal
    },
    props:{
      action:{
        type:Boolean,
        default:true
      }
    },
    data () {
      return {
        description: '商城订单管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'订单编码',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'订单日期',
            align:"center",
            dataIndex: 'malldate'
          },
          {
            title:'订单金额',
            align:"center",
            dataIndex: 'mny'
          },
          // {
          //   title:'订单客户',
          //   align:"center",
          //   dataIndex: 'customer'
          // },
          {
            title:'客户',
            align:"center",
            dataIndex: 'customername'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'vmemo'
          },
          {
            title:'总数量',
            align:"center",
            dataIndex: 'ntotalnum'
          },
          {
            title:'收货地址',
            align:"center",
            dataIndex: 'chreceivead'
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'联系人',
            align:"center",
            dataIndex: 'kman'
          },
          {
            title:'订单状态',
            align:"center",
            dataIndex: 'mallstatus',
            dictCode:"sczt",
            customRender:function (text) {
              if(text==0){
                return "提交";
              }else if(text==1){
                return "待支付";
              }else if(text==2){
                return "支付完成";
              }else if(text==3){
                return "待发货";
              }else if(text==4){
                return "已发货";
              }else if(text==5){
                return "完成";
              }else{
                return text;
              }
            }
          },
          {
            title:'审批状态',
            align:"center",
            dataIndex: 'actstatus',
            customRender:function (text) {
              if(text==0){
                return "自由态";
              }else if(text==1){
                return "审批中";
              }else if(text==2){
                return "审批通过";
              }else if(text==3){
                return "审批失败";
              }else{
                return text;
              }
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/mallorder/erpMallorder/list",
          delete: "/mallorder/erpMallorder/delete",
          deleteBatch: "/mallorder/erpMallorder/deleteBatch",
          exportXlsUrl: "/mallorder/erpMallorder/exportXls",
          importExcelUrl: "mallorder/erpMallorder/importExcel",

        },
        serviceName: 'erpMallorderService',
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    mounted(){
      this.columns=this.action?this.columns:this.columns.slice(0,this.columns.length-1)
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:'订单编码',dictCode:''})
        fieldList.push({type:'datetime',value:'malldate',text:'订单日期'})
        fieldList.push({type:'string',value:'mny',text:'订单金额',dictCode:''})
        fieldList.push({type:'string',value:'customer',text:'订单客户',dictCode:''})
        fieldList.push({type:'string',value:'customername',text:'客户',dictCode:''})
        fieldList.push({type:'string',value:'vmemo',text:'备注',dictCode:''})
        fieldList.push({type:'int',value:'mallstatus',text:'订单状态',dictCode:'sczt'})
        fieldList.push({type:'int',value:'actstatus',text:'审批状态',dictCode:'spzt'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
